/*
 *
 * django-codenerix
 *
 * Codenerix GNU
 *
 * Project URL : http://www.codenerix.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

 // Default definitions
$.notify.defaults({
    autoHide: false,
    clickToHide: false,
});

// Modified bootstrap style tu support basic text with ID
$.notify.addStyle("bootstrap_id", {
    html: "<div>" +
            "<div class='title' data-notify-html='title'/></div>" +
          "</div>",
    classes: {
    base: {
      "font-weight": "bold",
      "padding": "8px 15px 8px 14px",
      "text-shadow": "0 1px 0 rgba(255, 255, 255, 0.5)",
      "background-color": "#fcf8e3",
      "border": "1px solid #fbeed5",
      "border-radius": "4px",
      "white-space": "nowrap",
      "padding-left": "25px",
      "background-repeat": "no-repeat",
      "background-position": "3px 7px"
    },
    danger: {
      "color": "#B94A48",
      "background-color": "#F2DEDE",
      "border-color": "#EED3D7",
      "background-image": "url()"
    },
    success: {
      "color": "#468847",
      "background-color": "#DFF0D8",
      "border-color": "#D6E9C6",
      "background-image": "url()"
    },
    info: {
      "color": "#3A87AD",
      "background-color": "#D9EDF7",
      "border-color": "#BCE8F1",
      "background-image": "url()"
    },
    warning: {
      "color": "#C09853",
      "background-color": "#FCF8E3",
      "border-color": "#FBEED5",
      "background-image": "url()"
    },
    custom: {
      "color": "#3A87AD",
      "background-color": "#D9EDF7",
      "border-color": "#FFFFFF",
      "background-image": "url()"
    },
  }
});
// Modified bootstrap style tu support buttons with ID
$.notify.addStyle("bootstrap_id_button", {
  html: "<div>" +
          "<div class='clearfix'>" +
            "<div class='title' data-notify-html='title'/>" +
            "<div class='buttons'>" +
              "<button type='button' class='notifyjs-yes' data-notify-text='button'></button>" +
              "<button type='button' class='notifyjs-no'>Cancel</button>" +
            "</div>" +
          "</div>" +
        "</div>",
  classes: {
    base: {
      "font-weight": "bold",
      "padding": "8px 15px 8px 14px",
      "text-shadow": "0 1px 0 rgba(255, 255, 255, 0.5)",
      "background-color": "#fcf8e3",
      "border": "1px solid #fbeed5",
      "border-radius": "4px",
      "white-space": "nowrap",
      "padding-left": "25px",
      "background-repeat": "no-repeat",
      "background-position": "3px 7px"
    },
    danger: {
      "color": "#B94A48",
      "background-color": "#F2DEDE",
      "border-color": "#EED3D7",
      "background-image": "url()"
    },
    success: {
      "color": "#468847",
      "background-color": "#DFF0D8",
      "border-color": "#D6E9C6",
      "background-image": "url()"
    },
    info: {
      "color": "#3A87AD",
      "background-color": "#D9EDF7",
      "border-color": "#BCE8F1",
      "background-image": "url()"
    },
    warning: {
      "color": "#C09853",
      "background-color": "#FCF8E3",
      "border-color": "#FBEED5",
      "background-image": "url()"
    },
    custom: {
      "color": "#3A87AD",
      "background-color": "#D9EDF7",
      "border-color": "#FFFFFF",
      "background-image": "url()"
    },
  }
});

function inotify(text,alarm,id,quick) {
    if (quick==true) {
        var showDuration=0;
    } else {
        var showDuration=400;
    }
    $.notify({
        title:"<span id='notify"+id+"' notify-id='"+id+"' notify-kind='"+alarm.kind+"'>"+text+"</span>",
        button:"OK",
    },{
        className:alarm.style,
        style:"bootstrap_id",
        position:"bottom right",
        showDuration: showDuration,
        hideDuration: 0,
    });
}

function inotify_button(text,alarm,button,id,quick) {
    if (quick==true) {
        var showDuration=0;
    } else {
        var showDuration=400;
    }
    $.notify({
        title:"<span id='notify"+id+"' notify-id='"+id+"' notify-kind='"+alarm.kind+"'>"+text+"</span>",
        button:button
    },{
        className:alarm.style,
        style:"bootstrap_id_button",
        position:"bottom right",
        showDuration: showDuration,
        hideDuration: 0,
    });
}
function inotify_close(id) {
    $('#notify'+id).parent().parent().trigger('notify-hide');
}

function getContrastYIQ(hexcolor){
    var r = parseInt(hexcolor.substr(0,2),16);
    var g = parseInt(hexcolor.substr(2,2),16);
    var b = parseInt(hexcolor.substr(4,2),16);
    var yiq = ((r*299)+(g*587)+(b*114))/1000;
    return (yiq >= 128) ? 'black' : 'white';
}

//listen for click events from this style
$(document).on('click', '.notifyjs-bootstrap_id-base', function() {
    // Get ID
    var id=$(this).find('.title').find('span').attr('notify-id');
    var kind=$(this).find('.title').find('span').attr('notify-kind');
    // Show message
    // console.log("Close alert ID: "+id);
    var scope = angular.element('#alarms').scope()
    scope.notify_hide(id,kind);
    // Hide notification
    $(this).trigger('notify-hide');
});
$(document).on('click', '.notifyjs-no', function() {
    // Get ID
    var id=$(this).parent().parent().parent().find('.title').find('span').attr('notify-id');
    var kind=$(this).parent().parent().parent().find('.title').find('span').attr('notify-kind');
    // Show message
    // console.log("Close alert ID: "+id);
    var scope = angular.element('#alarms').scope()
    scope.notify_no(id,kind);
    // Hide notification
    $(this).trigger('notify-hide');
});
$(document).on('click', '.notifyjs-yes', function() {
    // Get ID
    var id=$(this).parent().parent().parent().find('.title').find('span').attr('notify-id');
    var kind=$(this).parent().parent().parent().find('.title').find('span').attr('notify-kind');
    // Show message
    // console.log("Accepted alert ID:"+id);
    var scope = angular.element('#alarms').scope()
    scope.notify_yes(id,kind);
    // Hide notification
    $(this).trigger('notify-hide');
});
